<?php

namespace ANPAdmin  {

   /***********************************************************
    * 
    ***********************************************************/
   class PProperty extends \PRokkoMVC\PRokkoModel {
      
      /***********************************************************
       *
       ***********************************************************/
      public function getTopProperties($pCount){
          
         return $this->wpdb->get_results("
            SELECT 
               Property.name,
               Property.bookingtool_url as url,
               TopProperty.rank
            FROM 
               anp_top_properties TopProperty
               JOIN anp_properties Property ON Property.id = TopProperty.anp_property_id
            ORDER BY
               TopProperty.rank
            LIMIT {$pCount}
         ");
      }
      
      
      /***********************************************************
       *
       ***********************************************************/
      public function getProperties(){
      
         return $this->wpdb->get_results("
               SELECT
                  Property.id,
                  Property.name,
                  Property.city,
                  Property.state,
                  TopProperty.rank
               FROM
                  anp_properties Property
                  LEFT JOIN anp_top_properties TopProperty ON TopProperty.anp_property_id = Property.id
               ORDER BY
                  Property.name
               ");
      }
      
      
      /***********************************************************
       *
       ***********************************************************/
      public function getProperty($pId){
      
         $prop = $this->wpdb->get_results("
               SELECT
                  Property.id,
                  Property.name,
                  Property.bookingtool_url,
                  Property.address,
                  Property.city,
                  Property.state,
                  Property.zip,
                  Property.phone,
                  Property.gps_lat,
                  Property.gps_lon,
                  Property.thumbnail,
                  TopProperty.rank
               FROM
                  anp_properties Property
                  LEFT JOIN anp_top_properties TopProperty ON TopProperty.anp_property_id = Property.id
               WHERE
                  Property.id = {$pId}
               ");
         
         return $prop[0];
      }
      
      
      /***********************************************************
       *
       ***********************************************************/
      public function getPark(){
      
         $park = $this->wpdb->get_results("
               SELECT
                  Park.name,
                  Park.gps_lat,
                  Park.gps_lon
               FROM
                  anp_park Park
               LIMIT 1
               ");
         
         return $park[0];
      }
   }
}
